<%@ page pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>
<%@ page import="com.szboanda.platform.util.StringUtils"%>
<%@ page import="com.szboanda.platform.util.resources.Configuration"%>
<%
    request.setAttribute("pageTitle", "目录资源");
    request.setAttribute("userName", ActionHelper.getShareName());
    String op = request.getParameter("ACTION_OPERATE");
    if (!StringUtils.isEmpty(op)) {
        request.setAttribute("ACTION_OPERATE", op);
    }
    pageContext.setAttribute("resource_wjlj", Configuration.getProperty("datacenter.resource.upload.dir", ""));
    try {
%>
<%@ include file="/pages/ebcm/common/header.jsp" %>

<style>
<!--
.choosefile {
    display: block;
    width: 88px;
    height: 25px;
    overflow: hidden;
    text-align: center;
    background: url('${ctx}/skins/sjzx/images/choosefile.jpg') no-repeat;
}
.choosefile input {
    width: 0;
    height: 22px;
    filter: alpha(opacity=0);
    opacity: 0;
    border: none;
    margin-left: -5px;
    cursor: pointer;
}
#uploadStatus span, #uploadStatus a {
    display: block;
    height: 20px;
    line-height: 20px;
    float: left;
}
#uploadStatus a {margin-left: 5px;}
#progressbar {
    width: 100px;
    text-align: left;
    background: #CCEDFF;
}
#progressbar .pbar {
    background: #73C5FF;
    position: absolute;
}
#progressbar .ptext {
    width: 100%;
    text-align: center;
    position: absolute;
}
-->
</style>

<script type="text/javascript">
<!--
var wannaCancel = false;

var operate = function (oper, params) {

    switch (oper) {
        case "query":
            document.getElementById("opForm").submit();
            break;
        case "addNew":
            var id = findObj("fmdid").value;
        	window.location = '${ctx}/maintTSjzxXtzyxx.do?method=init&fmdid='+id;
            break;
        case "save":
            var fileName = window.frames['myFrame'].document.getElementById("uploadFileName").value;
        	var boot = window.frames['myFrame'].document.getElementById("boot").value;
    		var dir = window.frames['myFrame'].document.getElementById("dir").value;
    		findObj("bean.wjlj").value = boot;
    		findObj("bean.bcmc").value = dir+fileName;
    		submitForm(document.getElementById("opForm"));
            break;
        case "chooseFile":
            wannaCancel = false;
            window.setTimeout(function () {
                if ($("input[name=uploadFile]")[0].value) {
                    status("start");

                    // filename
                    var i = $("input[name=uploadFile]")[0].value.lastIndexOf('\\');
                    $("#filename").html($("input[name=uploadFile]")[0].value.substring(i + 1));

                    // random name
                    var random = (new Date().getTime() + "" + Math.random()).replace(".", "");
                    $("input[name=random]")[0].value = random;
                    
                    $("#uploadForm").submit();
                    
                    progress();
                }
            }, 500);
            break;
        case "deleteFile":
            if (window.confirm("确定删除?")) {
                wannaCancel = true;
                status("cancel");
                
                $("iframe[name=uploadIframe]").attr({src: null});
                var url = ctx + "/pages/ebcm/business/zyml/upload_handler.jsp";
                var _o = {
                    method: "delete",
                    uploadFile: $("input[name=uploadFile]")[0].value,
                    random: $("input[name=random]")[0].value
                };
                document.getElementById("uploadForm").reset();
                $.post(url, _o, function (returnString) {});
            }
            break;
    }
    
}

var status = function (c, params) {
    switch (c) {
        case "start":
            $("#uploadForm").css({display: "none"});
            $("#uploadStatus").css({display: ""});
            break;
        case "uploading":
            $("span.pbar").css({width: params.percent + "%"});
            $("span.ptext").html(params.percent + "%");
            break;
        case "finish":
            $("#progressbar").css({display: "none"});
            break;
        case "cancel":
            $("#uploadForm").css({display: ""});
            $("#uploadStatus").css({display: "none"});
            $("span.pbar").css({width: 0});
            $("#progressbar").css({display: ""});
            $("span.ptext").html("");
            break;
    }    
};

var progress = function () {
    var url = ctx + "/pages/ebcm/business/zyml/upload_handler.jsp";
    var _o = {
        method: "progress",
        uploadFile: $("input[name=uploadFile]")[0].value,
        random: $("input[name=random]")[0].value
    };
    $.post(url, _o, function (returnString) {
        
        eval("var o = " + returnString.trim());
        if (o) {
            var percent = o.current * 100 / o.total;
            if (!window.isNaN(percent)) {
                percent = Math.ceil(percent);
            } else {
                percent = 0;
            }
            status("uploading", {percent: percent});
            if (1 === o.finish) {
                if (wannaCancel) {
                    status("cancel");
                } else {
                    status("finish");
                }
            } else {
                window.setTimeout(function () {
                    progress();
                }, 10);
            }
        }
    });
};
//-->
</script>

<%@ include file="/pages/ebcm/common/middle1.jsp" %>

<input value="保存" type="button" class="btn" onclick="operate('save');"/>

<logic:notEmpty name="ACTION_OPERATE">
<c:set var="ActionMethod" value="${param.method}"/>
<logic:equal value="delete" name="ActionMethod"></logic:equal>
</logic:notEmpty>

<%@ include file="/pages/ebcm/common/middle2.jsp" %>
<%@ include file="/pages/ebcm/common/split.jsp" %>

<sql:query var="flList" dataSource="${dataSource}">
SELECT * FROM T_ADMIN_RMS_CD
WHERE SFYX = '1'
    AND FCDXH = '201001161346538876f99d20c24894a9f7c55968755dec'
</sql:query>

<html:form action="maintTSjzxXtzyxx" method="post" styleId="opForm">
 
	<input type="hidden" name="method"
        value="${empty tSjzxXtzyxxForm.map.bean.xh ? 'insert' : 'update'}" />
	<input type="hidden" name="fmdid"
        value="${empty param.fmdid ? tSjzxXtzyxxForm.map.bean.fl : param.fmdid }" />
    
	<html:hidden property="bean.xh" styleId="bean.xh" />	
	<html:hidden property="bean.wjmc" styleId="bean.wjmc" />
	<html:hidden property="bean.bcmc" styleId="bean.bcmc" />
	<html:hidden property="bean.wjlj" styleId="bean.wjlj"
        value="${empty tSjzxXtzyxxForm.map.bean.wjlj ? resource_wjlj : tSjzxXtzyxxForm.map.bean.wjlj}" />
    
    <table width="98%" align="center" cellspacing="0" id="list_table_1">
		 <tr>
			 <td class='td-lable' width="20%"><font color="red">*</font>分类：</td>
			 <td align="left" colspan="3">
                <html:select property="bean.fl" styleId="bean.fl"
                    value="${empty param.fmdid ? tSjzxXtzyxxForm.map.bean.fl : param.fmdid}">
                    <c:forEach var="fl" items="${flList.rows}">
                    <html:option value="${fl.XH}">${fl.CDMC}</html:option>
                    </c:forEach>
                </html:select>
			</td>
		 </tr>
        <tr>
            <td class='td-lable'>作者：</td>
            <td class='td-text' colspan="3">
                <html:text property="bean.zz" styleId="bean.zz"
                    onchange="return checkValid(this, 'STRING')" maxlength='50'
                    style="width: 240px;" />
            </td>
        </tr>
        <tr>
            <td class='td-lable'><font color="red">*</font>标题：</td>
            <td class='td-text' colspan="3">
                <html:text property="bean.bt" styleId="bean.bt"
                    onchange="return checkValid(this, 'STRING')" style="width: 240px;" />
            </td>
        </tr>
        <tr>
            <td class='td-lable'>主题词：</td>
            <td class='td-text' colspan="3">
                <html:text property="bean.ztc" styleId="bean.ztc"
                    onchange="return checkValid(this, 'STRING')" style="width: 240px;" />
            </td>
        </tr>
        <tr>
            <td class='td-lable'>上传人：</td>
            <td class='td-text' colspan="3">
                <html:text property="bean.scr" styleId="bean.scr"
                    onchange="return checkValid(this, 'STRING')" maxlength='50'
                    style="width: 240px;" />
            </td>
        </tr>
        <c:if test="${empty tSjzxXtzyxxForm.map.bean.wjmc }">
        <c:set var="uploadFlag" value="&uploadFlag=0"></c:set>
        </c:if>
		 
        <tr style="display: none;">
            <td class='td-lable'>上传文件：</td>
            <td class='td-text' colspan="3">
                <iframe src="${ctx }/pages/ebcm/business/zyml/zymlupload.jsp?uploadFileName=${tSjzxXtzyxxForm.map.bean.wjmc }&ACTION_OPERATE=${ACTION_OPERATE}${uploadFlag }" frameborder="0" id="myFrame"
                    style="width : 100%;height: 25px;border-width: 0px;margin: opx;padding: 0px; display: none;"
                    ></iframe>
            </td>
        </tr>
		 
		 <c:if test="${ACTION_OPERATE eq 'V'}">
		  <tr>
			 <td class='td-lable'>文件大小：</td>
			 <td class='td-text' colspan="3"><html:text property="bean.wjdx" styleId="bean.wjdx" onchange="return checkValid(this, 'STRING')"  maxlength='50' style="width: 240px;"/></td>
		 </tr>
		  <tr>
			 <td class='td-lable'>文件类型：</td>
			 <td class='td-text' colspan="3"><html:text property="bean.wjgs" styleId="bean.wjgs" onchange="return checkValid(this, 'STRING')"  maxlength='50' style="width: 240px;"/></td>
		 </tr>
		  <tr>tt
			 <td class='td-lable'>上传时间：</td>
			 <td class='td-text' colspan="3"><html:text property="bean.scsj" styleId="bean.scsj" onchange="return checkValid(this, 'STRING')"  maxlength='50' style="width: 240px;"/></td>
		 </tr>
		 </c:if>
	</table>
</html:form>
<br />
<table width="98%" align="center" cellspacing="0" id="list_table_1">
    <tr>
        <td class='td-lable' width="20%">上传文件：</td>
        <td class='td-text' colspan="3">
            <form action="${ctx}/pages/ebcm/business/zyml/upload_handler.jsp"
                id="uploadForm" method="post" enctype="multipart/form-data" target="uploadIframe">
                <span class="choosefile"><input type="file" name="uploadFile" onchange="operate('chooseFile')" /></span>
                <input type="hidden" name="random" />
            </form>
            <div id="uploadStatus" style="display: none;">
                <span id="filename"></span>
                <span id="progressbar"><span class="pbar"></span><span class="ptext"></span></span>
                <a href="javascript:operate('deleteFile')">删除</a>
            </div>
        </td>
    </tr>
</table>
<iframe name="uploadIframe" style="display: none;"></iframe>

<script>
<!--
var us = findObj("bean.xh").value;
if(us === ''){
	findObj("bean.scr").value = "${userName}";
}
//-->
</script>

<%}catch(Exception e){out.println(e.toString());} %>
<%@ include file="/pages/ebcm/common/footer.jsp" %>
